#include "PlayerProfile.h"

PlayerProfile::PlayerProfile()
:m_raceType(Race_Human)
,m_curBattleHero(NULL)
,m_actionNum(GAME_ACTION_START_NUM)
{

}

void PlayerProfile::decActionNum()
{
	--m_actionNum;
	for (PlayerProfileListenerList::iterator iter = m_listeners.begin();iter != m_listeners.end();++iter)
	{
		PlayerProfileListener* _l = *iter;
		_l->tellActionNumChanged(m_actionNum);
	}
}

void PlayerProfile::incActionNum()
{
	++m_actionNum;
	for (PlayerProfileListenerList::iterator iter = m_listeners.begin();iter != m_listeners.end();++iter)
	{
		PlayerProfileListener* _l = *iter;
		_l->tellActionNumChanged(m_actionNum);
	}
}

void PlayerProfile::setActionNum(int actionNum)
{
	m_actionNum = actionNum;
	for (PlayerProfileListenerList::iterator iter = m_listeners.begin();iter != m_listeners.end();++iter)
	{
		PlayerProfileListener* _l = *iter;
		_l->tellActionNumChanged(m_actionNum);
	}
}

void PlayerProfile::registerListener( PlayerProfileListener* l )
{
	m_listeners.push_back(l);
}

void PlayerProfile::unregisterListener( PlayerProfileListener* l )
{
	for (PlayerProfileListenerList::iterator iter = m_listeners.begin();iter != m_listeners.end();++iter)
	{
		PlayerProfileListener* _l = *iter;
		if (_l == l)
		{
			m_listeners.erase(iter);
			break;
		}
	}
}

PlayerProfileManager::PlayerProfileManager()
{

}

PlayerProfileManager::~PlayerProfileManager()
{
	for (PlayerProfileList::iterator iter = m_profiles.begin();iter != m_profiles.end();++iter)
	{
		PlayerProfile* profile = *iter;
		delete profile;
	}

	 m_profiles.clear();
}

PlayerProfile* PlayerProfileManager::createPlayerProfile()
{
	PlayerProfile* profile = new PlayerProfile;
	m_profiles.push_back(profile);

	return profile;
}